{% extends 'base.html' %}

{% load static %}

{% block title %}TRAM - Threat Report ATT&CK Mapper{% endblock %}

{% block body %}
<h1>ML Admin</h1>
<div class="container row flex-nowrap">
  <div class="col-sm">
    <h3>Sentences Per Technique</h3>
    <table id="technique-sentence-table" class="table table-striped table-hover" aria-label="Technique sentence table">
      <tbody>
        <tr>
          <th scope="col">#</th>
          <th scope="col">Technique ID</th>
          <th scope="col">Technique Name</th>
          <th scope="col">Accepted Sentences</th>
          <th scope="col">Pending Sentences</th>
          <th scope="col">Total Sentences</th>
        </tr>
        {% for t in techniques %}
        <tr>
          <td>{{ forloop.counter }}</td>
          <td><a href="{{ t.attack_url }}">{{ t.attack_id }}</a></td>
          <td>{{ t.name }}</td>
          <td><a href="/ml/techniques/{{t.attack_id}}">{{ t.accepted_sentences }}</a></td>
          <td><a href="/ml/techniques/{{t.attack_id}}">{{ t.pending_sentences }}</a></td>
          <td><a href="/ml/techniques/{{t.attack_id}}">{{ t.total_sentences }}</a></td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  <div class="col-sm">
    <div>
      <h3>ML Models</h3>
      <table id="ml-models-table" class="table table-striped" aria-label="ml models table">
        <tbody>
          <tr>
            <th scope="col">Model Name</th>
            <th scope="col">Last Trained</th>
            <th scope="col">Accuracy (f1&nbspScore)</th>
            <th scope="col">Trained Techniques</th>
          </tr>
          {% for model in models %}
            <tr>
              <td><a href="/ml/models/{{model.model_key}}">{{ model.name }}</a></td>
              <td>{{ model.last_trained }}</td>
              <td>{{ model.average_f1_score }}%</td>
              <td>{{model.trained_techniques_count}}</td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    <div>
      <h3>ML Settings <a class="btn btn-primary-outline" href="/admin/constance/config/">Manage</a></h3>
      <table id="ml-settings-table" class="table table-striped" aria-label="Settings table">
        <tbody>
          <tr>
            <th scope="col">Setting</th>
            <th scope="col">Value</th>
            <th scope="col">Note</th>
          </tr>
          <tr>
            <td>ML_ACCEPT_THRESHOLD</td>
            <td>{{ML_ACCEPT_THRESHOLD}}</td>
            <td>Exclude Attack Techniques with less than the specified number of accepted sentences</td>
          </tr>
          <tr>
            <td>ML_CONFIDENCE_THRESHOLD</td>
            <td>{{ML_CONFIDENCE_THRESHOLD}}</td>
            <td>Do not proposed Attack Techniques if the confidence is below the threshold</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>

{% endblock %}
